package com.myk.game.gobangchess.services;

import com.myk.game.gobangchess.DataManager;
import com.myk.game.gobangchess.constants.AppConfig;

import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;

public class SocketServer {
    public static void start() {
        try (ServerSocket ss = new ServerSocket(Integer.parseInt(AppConfig.SOCKET_PORT))) {
            System.out.println("======《逆界黑白》服务端启动,服务地址" + InetAddress.getLocalHost().getHostAddress() + ",监听端口" + AppConfig.SOCKET_PORT + "======");
            DataManager.printRoomList(); //打印当前已经配置的房间列表
            System.out.println();
            while (true) {
                Socket socket = ss.accept();
                //System.out.println("接收到一个新的链接");
                new Thread(new LoginService(socket)).start();
            }
        }
        catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
